/*
 * Copyright 2007 Agile Plugins Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.agileplugins.monkey;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.MultiLineLabelUI;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class TextFieldDialog extends DialogWrapper {
    private Logger logger = Logger.getInstance(getClass().getName());

    private String message;
    private Icon icon;
    private JTextField jtextField;

    public TextFieldDialog(String title, String message, Project project) {
        super(project, false);
        setTitle(title);
        this.message = message;
        setButtonsAlignment(0);
        init();
    }

    protected Action[] createActions() {
        ArrayList arraylist = new ArrayList();
        arraylist.add(getOKAction());
        arraylist.add(getCancelAction());
        return (Action[]) arraylist.toArray(new Action[arraylist.size()]);
    }

    protected JComponent createNorthPanel() {
        JLabel jlabel = new JLabel(message);
        jlabel.setUI(new MultiLineLabelUI());
        JPanel jpanel = new JPanel(new BorderLayout());
        jpanel.add(jlabel, "North");
        jlabel.setIcon(UIManager.getIcon("OptionPane.questionIcon"));
        jlabel.setIconTextGap(10);
        jtextField = new JTextField();
        jpanel.add(new JScrollPane(jtextField), "Center");
        jpanel.add(Box.createVerticalStrut(7), "South");
        return jpanel;
    }

    public JComponent getPreferredFocusedComponent() {
        return jtextField;
    }

    public void setText(String text) {
        jtextField.setText(text);
    }

    public String getText() {
        return jtextField.getText();
    }

    protected JComponent createCenterPanel() {
        return null;
    }
}

